package com.diver.flinkdemo.Trd.yjy;

import com.alibaba.fastjson.JSONObject;
import com.diver.flinkdemo.entity.ResultConfig;
import com.diver.flinkdemo.service.IHttpService;
import com.diver.flinkdemo.service.impl.HttpServiceImpl;
import com.diver.flinkdemo.utils.FlinkThreadUtil;
import com.diver.flinkdemo.utils.TrdUrlUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.entity.ContentType;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author liuC
 * @Date 2022/8/25 0025 11:21
 * @Describe
 */
@Slf4j
public class YJYController {
    private FlinkThreadUtil threadUtil = new FlinkThreadUtil();

    private IHttpService httpService = new HttpServiceImpl();
    /**
     * 壹教云推送数据
     * @param data
     */
    public void YJYDeal(String data){
        threadUtil.threadPoolExecutor().submit(new Runnable() {
            @Override
            public void run() {
                log.info("壹教云推送 - 接收数据：{} 时间{}", data, new Date().getTime());
                JSONObject jo = JSONObject.parseObject(data);
                String url = TrdUrlUtil.YJY_URL + jo.getString("url");
                Map<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/json");
                ContentType contentType = ContentType.APPLICATION_JSON;
                ResultConfig<String> result = httpService.doStringEntityPost(url, headers, jo.getString("params"), contentType, "utf-8");
                log.info("壹教云平台推送数据{} 返回:{}", url, result);
            }
        });
    }
}
